# -*- coding: utf-8 -*-
# @File : test.py
# @Time : 2024/5/14 11:21
# @Author : syq
# @Email : 1721169065@qq.com
# @Software: PyCharm
print('测试远程gitee')

from playwright.sync_api import sync_playwright

# with sync_playwright() as p:
#     browser = p.chromium.launch(headless=False)          # 启动 chromium 浏览器
#     page = browser.new_page()              # 打开一个标签页
#     page.goto("https://www.baidu.com")     # 打开百度地址
#     print(page.title())                    # 打印当前页面title
#     page.click("input[name='wd']")       # 点击输入框
#     page.fill("input[name='wd']", "chromium")  # 在输入框输入浏览器名字
    # page.screenshot(path=f'example-{p.chromium.name}.png')
    # browser.close()
input('1....')
#启动playwright driver 进程
p=sync_playwright().start()
input('2....')
#启动浏览器，返回 Browser 类型对象
browser =p.chromium.launch(headless=False)
#创建新页面，返回 Page 类型对象
page = browser.new_page()
page.goto("https://www.byhy.net/_files/stock1.html")
print(page.title()) #打印网页标题栏

#输入通讯，点击查询。这是定位与操作，是自动化重点，后文详细讲解
page.locator('#kw').fill('通讯') #输入通讯
page.locator('#go').click() # 点击查询

#打印所有搜索内容
lcs=page.locator(".result-item").all()
for lc in lcs:
    print(lc.inner_text())
input('3....')
# 关闭浏览器
browser.close()
input('4....')
#关闭 playwright driver 进程
p.stop()